<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<%@include file="/view/resource.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/base.css">
	<script type="text/javascript" src="${ctx}/js/common/utility.js"></script>
	<style type="text/css">

		.panel-tool a.layout-button-up {
			display: none;
		}
	</style>
</head>
<body class="topjui-layout">
<!-- Search panel start -->
<div class="ui-search-panel" style="height: 90px;" title="操作框"
     data-options="region:'north',iconCls:'fa fa-search',border:false,split:false">
	<form id="searchForm1">
		<p class="ui-fields" style="min-width:1050px">
			<label class="ui-label">显示名称:</label><input id="equipName" name="equipName" data-toggle="topjui-textbox"
			                                            style="width:180px;">
			<label class="ui-label">设备号:</label><input id="simNo" name="simNo" data-toggle="topjui-textbox"
			                                           style="width:180px;">
			<label class="ui-label">定位时间</label>
			<input name="startTime" id="startTimeSearch"
			       class="topjui-datetimebox" editable="false"
			       data-options=" width:180">
			<label class="ui-label">至</label>
			<input name="endTime" id="endTimeSearch"
			       class="topjui-datetimebox" editable="false"
			       data-options=" width:180">

			<a href="#" id="btn-search" class="topjui-menubutton" data-options="iconCls:'fa fa-search',
           btnCls:'topjui-btn'" style="margin-left: 5px;">搜索</a>

			<a href="#" id="btn-export" class="topjui-menubutton" data-options="iconCls:'fa fa-cloud-download',
           btnCls:'topjui-btn'" style="margin-left: 5px;">导出</a>
		</p>
	</form>
</div>
<!--  Search panel end -->

<!-- DataList  -->
<div region="center" border="false">
	<table id="data-list"></table>
</div>
<script type="text/javascript" src="${ctx}/js/common/package.js"></script>
<script type="text/javascript" src="${ctx}/js/common/base.js?v=11"></script>
<script type="text/javascript" src="${ctx}/js/common/DataGrid.js"></script>
<script type="text/javascript">
	// 对Date的扩展，将 Date 转化为指定格式的String
	// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
	// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
	// 例子：
	// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
	// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
	Date.prototype.Format = function (fmt) { //author: meizz
		var o = {
			"M+": this.getMonth() + 1, //月份
			"d+": this.getDate(), //日
			"h+": this.getHours(), //小时
			"m+": this.getMinutes(), //分
			"s+": this.getSeconds(), //秒
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度
			"S": this.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	}

	$(function () {
		$("#startTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd") + " 00:00:00");
		$("#endTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd") + " 23:59:59");

		$("#btn-search").click(function () {
			var simNo = $("#simNo").val();
			/*	if (simNo == null || simNo.length == 0) {
			 $.iMessager.alert("提示", "请输入设备号", 'messager-warning');
			 return false;
			 }*/
			if (validateDate()) {
				var equipName = $("#equipName").val();
				var startTime = $("#startTimeSearch").datetimebox('getText');
				var endTime = $("#endTimeSearch").datetimebox('getText');
				var param = {
					equipName: equipName,
					simNo: simNo,
					startTime: startTime,
					endTime: endTime,
					dataListForView: true
				};
				$('#data-list').datagrid('reload', param);
			}
		});


		$("#btn-export").click(function () {
			if (validateDate()) {
				var simNo = $("#simNo").val();
				var equipName = $("#equipName").val();
				var startTime = $("#startTimeSearch").datetimebox('getText');
				var endTime = $("#endTimeSearch").datetimebox('getText');
				//var param = {equipName: equipName, simNo: simNo, startTime: startTime, endTime: endTime};
				var url = '${ctx}/hisGps/exportHisGps?equipName=' + equipName + '&simNo=' + simNo + '&startTime=' + startTime + '&endTime=' + endTime;
				window.location.href = url;
			}
		});

	});


	function validateDate() {
		var startTime = $("#startTimeSearch").datetimebox('getText');
		var endTime = $("#endTimeSearch").datetimebox('getText');
		startTime = Utility.stringToDate(startTime);
		endTime = Utility.stringToDate(endTime);
		if (isNaN(startTime.getTime()) || isNaN(endTime.getTime())) {
			$.iMessager.alert('提示', '非法的日期格式', 'messager-warning');
			return false;
		}
		var today = new Date();

		var date1 = new Date(startTime.getFullYear(), startTime.getMonth(), startTime.getDate());
		var date2 = new Date(endTime.getFullYear(), endTime.getMonth(), endTime.getDate());
		var date3 = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
		if (startTime > today) {
			$.iMessager.alert('提示', '开始日期不能大于当前日期', 'messager-warning');
			return false;
		}
		if (date2 > date3) {
			$.iMessager.alert('提示', '结束日期不能大于今天日期', 'messager-warning');
			return false;
		}

		if (startTime >= endTime) {
			$.iMessager.alert('提示', '开始时间不能大于等于结束时间', 'messager-warning');
			return false;
		}

		var iDays = Utility.getDay(date1, date2);
		if (iDays > 2) {
			$.iMessager.alert('提示', '一次只能操作不超过两天的历史数据', 'messager-warning');
			return false;
		}
		return true;
	}
</script>
<script type="text/javascript" src="${ctx}/js/history/history.js"></script>
</body>
</html>
